import { Injectable } from '@angular/core';
import { BasicService } from 'src/app/shared/service/basic.service';
import { Observable } from 'rxjs';
import { Banner, SongSheet, Singer, HotTag } from '../entity';
import { map } from 'rxjs/operators';
import { HttpClient } from '@angular/common/http';

@Injectable()
export class HomeResolveService extends BasicService {

  constructor(private http: HttpClient) {
    super();
  }

  /** 获取轮播图数据 */
  getBanners(): Observable<Banner[]> {
    const url = this.api('banner');
    return this.http.get(url)
      .pipe(map((res: { banners: Banner[] }) => res.banners));
  }

  /** 获取热门推荐分类 */
  getHotTags(): Observable<HotTag[]> {
    const url = this.api('playlist/hot');
    return this.http.get(url)
      .pipe(map((res: { tags: HotTag[] }) => {
        // 返回前 5 个
        return res.tags.slice(0, 5);
      }));
  }

  /** 获取热门推荐歌单 */
  getPersonalSongSheets(): Observable<SongSheet[]> {
    const url = this.api('personalized?limit=16');
    return this.http.get(url)
      .pipe(map((res: { result: SongSheet[] }) => res.result));
  }

}
